home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / WinCE / Src / Source / CBasicApp.cp next >
Encoding:
Text File  |  2000-06-23  |  4.7 KB  |  223 lines

  1. //
  2. //    The WinCE emulation hack. 
  3. //
  4. //    All presentation and no substance. Lame. 
  5. //
  6. //    Copyright 2000, by Mark Darling
  7. //
  8.  
  9. #include "CBasicApp.h"
  10.  
  11. #include <LGrowZone.h>
  12. #include <PP_Messages.h>
  13. #include <PP_Resources.h>
  14. #include <UDrawingState.h>
  15. #include <UMemoryMgr.h>
  16. #include <URegistrar.h>
  17.  
  18. #include <LWindow.h>
  19. #include <LCaption.h>
  20. #include <LIconPane.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23.  
  24.     // Constant declarations
  25. const ResIDT    PPob_SampleWindow            = 128;
  26. const ResIDT    PPob_WarningWindow            = 129;
  27.  
  28. // ===========================================================================
  29. //    • main
  30. // ===========================================================================
  31.  
  32. int main()
  33. {                            
  34.         // Set Debugging options
  35.     SetDebugThrow_(debugAction_Alert);
  36.     SetDebugSignal_(debugAction_Alert);
  37.  
  38.         // Initialize Memory Manager. Parameter is the number of
  39.         // master pointer blocks to allocate
  40.     InitializeHeap(3);
  41.     
  42.         // Initialize standard Toolbox managers
  43.     UQDGlobals::InitializeToolbox(&qd);
  44.     
  45.         // Install a GrowZone to catch low-memory situations    
  46.     new LGrowZone(20000);
  47.  
  48.         // Create the application object and run
  49.     CBasicApp    theApp;
  50.     theApp.Run();
  51.     
  52.     return 0;
  53. }
  54.  
  55.  
  56. // ---------------------------------------------------------------------------
  57. //    • CBasicApp                                        [public]
  58. // ---------------------------------------------------------------------------
  59. //    Application object constructor
  60.  
  61. CBasicApp::CBasicApp()
  62. {
  63.     RegisterClasses();
  64. }
  65.  
  66.  
  67. // ---------------------------------------------------------------------------
  68. //    • ~CBasicApp                                    [public, virtual]
  69. // ---------------------------------------------------------------------------
  70. //    Application object destructor
  71.  
  72. CBasicApp::~CBasicApp()
  73. {
  74.     // Nothing
  75. }
  76.  
  77.  
  78. // ---------------------------------------------------------------------------
  79. //    • StartUp                                        [protected, virtual]
  80. // ---------------------------------------------------------------------------
  81. //    Perform an action in response to the Open Application AppleEvent.
  82. //    Here, issue the New command to open a window.
  83.  
  84. void
  85. CBasicApp::StartUp()
  86. {
  87.     ObeyCommand(cmd_New, nil);
  88. }
  89.  
  90.  
  91. // ---------------------------------------------------------------------------
  92. //    • ObeyCommand                                    [public, virtual]
  93. // ---------------------------------------------------------------------------
  94. //    Respond to Commands. Returns true if the Command was handled, false if not.
  95.  
  96. Boolean
  97. CBasicApp::ObeyCommand(
  98.     CommandT    inCommand,
  99.     void*        ioParam)
  100. {
  101.     Boolean        cmdHandled = true;    // Assume we'll handle the command
  102.  
  103.     switch (inCommand) {
  104.  
  105.         case cmd_New: {
  106.             LWindow* theWindow = LWindow::CreateWindow(PPob_SampleWindow, this);
  107.             ThrowIfNil_(theWindow);
  108.  
  109.             theWindow->Show();
  110.  
  111.             unsigned long Dummy;
  112.             Delay( 150, &Dummy );
  113.             // Create the dialog handler.
  114.  
  115.             StDialogHandler theHandler( PPob_WarningWindow, this );
  116.  
  117.             // Get the dialog.
  118.  
  119.             LWindow *theDialog;
  120.  
  121.             theDialog = theHandler.GetDialog();
  122.  
  123.             Assert_( theDialog != nil );            
  124.             
  125.             theDialog->Show();
  126.  
  127.             while ( true ) {
  128.  
  129.               // Handle dialog messages.
  130.  
  131.               MessageT theMessage = theHandler.DoDialog();
  132.  
  133.               
  134.  
  135.               if ( theMessage == 900 ) {
  136.  
  137.                 DoQuit( 0 );
  138.                 
  139.                 break;
  140.  
  141.                 
  142.  
  143.               } else if ( theMessage == 901 ) {
  144.                 theDialog->DoClose();
  145.                 LPicture *pPicture =                                        // cache LTabsControl for speed
  146.                     dynamic_cast< LPicture *> (theWindow->FindPaneByID(5));
  147.                 ThrowIfNil_(pPicture);
  148.                 
  149.                 pPicture->Show();
  150.                 break;
  151.  
  152.               }
  153.  
  154.             }            
  155.             
  156.             
  157.             
  158.             
  159.             
  160.             
  161.             
  162.             
  163.             break;
  164.         }
  165.  
  166.         default: {
  167.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  168.             break;
  169.         }
  170.     }
  171.     
  172.     return cmdHandled;
  173. }
  174.  
  175.  
  176. // ---------------------------------------------------------------------------
  177. //    • FindCommandStatus                                [public, virtual]
  178. // ---------------------------------------------------------------------------
  179. //    Determine the status of a Command for the purposes of menu updating.
  180.  
  181. void
  182. CBasicApp::FindCommandStatus(
  183.     CommandT    inCommand,
  184.     Boolean&    outEnabled,
  185.     Boolean&    outUsesMark,
  186.     UInt16&        outMark,
  187.     Str255        outName)
  188. {
  189.     switch (inCommand) {
  190.  
  191.         case cmd_New: {
  192.             outEnabled = true;
  193.             break;
  194.         }
  195.  
  196.         default: {
  197.             LApplication::FindCommandStatus(inCommand, outEnabled,
  198.                                             outUsesMark, outMark, outName);
  199.             break;
  200.         }
  201.     }
  202. }
  203.  
  204.  
  205. // ---------------------------------------------------------------------------
  206. //    • RegisterClasses                                [protected]
  207. // ---------------------------------------------------------------------------
  208. //    To reduce clutter within the Application object's constructor, class
  209. //    registrations appear here in this seperate function for ease of use.
  210.  
  211. void
  212. CBasicApp::RegisterClasses()
  213. {
  214.     RegisterClass_(LWindow);
  215.     RegisterClass_(LCaption);
  216.     RegisterClass_(LDialogBox);
  217.     RegisterClass_(LStdButton); 
  218.     RegisterClass_(LPane);
  219.     RegisterClass_(LIconPane);
  220.     RegisterClass_(LPicture);
  221. }
  222.  
  223.